package ShenBlueInc.Sql;

public class Login_inc {
/*该类主要写登陆注册的sql语句*/
	SqlConnect conn=new SqlConnect();
	/**
	 * 查询数据库中是否有指定用户
	 * @param name
	 * @param password
	 * @return 0 or 1
	 */
	public int SelectLogin(String name,String password) {
		String sql="select count(User_id) from `User` where User_telephone = ?  and User_Password=?";
		
		return Integer.parseInt(conn.OneItem(sql, name,password).toString());
	}
	/**
	 * 查询所有用户数据
	 * @param name
	 * @param password
	 * @return
	 */
	public Object[] SelectMsg(String name,String password){
		String sql="select User_id,User_telephone,IFNULL(User_name,\"\"),User_Password,IFNULL(User_email,\"\"),IFNULL(User_fullname,\"\") from `User` where User_telephone = ?  and User_Password= ? ";
		System.out.println(name+"  "+password);
		return conn.RowItem(sql, name,password);
		
	}
	/**
	 * 查看指定手机号是否存在
	 * @param telePhone
	 * @return
	 */
	public int SelectPhone(String telePhone) {
		String sql="select count(User_id) from `User` where User_telephone=?";
		return Integer.parseInt(conn.OneItem(sql, telePhone).toString());
	}
	/**
	 * 插入用户数据
	 * @param tel
	 * @param Pwd
	 * @return
	 */
	public int Add_User(String tel,String Pwd,String safe) {
		String sql="insert into `User`(User_telephone,User_Password,User_safe) values(?,?,?)";
		return conn.DelUpInsert(sql, tel,Pwd,safe);
	}
	/**
	 * 根据密保修改密码
	 * @param tel
	 * @param safe
	 * @param newPwd
	 * @return
	 */
	public int forget(String tel,String safe,String newPwd) {
		String sql="update `User` set User_Password=? where User_telephone=? and User_safe=?";
		return conn.DelUpInsert(sql, newPwd,tel,safe);
	}
}
